/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—06—19
 * Time: 18:28
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/listBooks.jsp")
public class ListAllBookServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();

        ArrayList<Book> AllBook = BookDB.getAll();
        if (AllBook!=null && AllBook.size()>0){
            for (int i=0;i<AllBook.size();i++){
                Book bk=AllBook.get(i);
                out.println("书名："+bk.getName()+"&nbsp;&nbsp;价格："+bk.getPrice()+"&nbsp;&nbsp;");
                out.println("<a href=\"cartBookServlet?id="+bk.getId()+"\">加入购物车<a>&nbsp;&nbsp;");
                out.println("<a href=\"listCart.jsp\">显示购物车<a><br><br>");
            }
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}